<?php
namespace app\admin\controller;

use think\Db;

class Config extends Base
{
    private $tn = 'system_config';

    public function _empty($action)
    {
        if ($this->post) {
            foreach ($this->post as $config => $value) {
                Db::table($this->tn)->where('config', $config)->setField('value', $value);
            }
            $this->returnAPI('保存成功', 0);
        }
        $configs = Db::table($this->tn)->column('value', 'config');
        return $this->fetch($action, ['configs' => $configs]);
    }

    public function pwd()
    {
        if ($this->post) {
            if (db('admin')->where(['id' => $this->post['admin_id'], 'password' => $this->post['oldpwd']])->setField('password', $this->post['newpwd'])) {
                $this->returnAPI('密码修改成功', 0);
            }
            $this->returnAPI('原密码有误');
        }
        return $this->fetch('', ['admin_id' => session('admin_id'), 'oldpwd' => get_field('admin_admin', session('admin_id'), 'password')]);
    }
}
